//
//  ProfileViewController.m
//  SinaWeibo
//
//  Created by Apple on 16/8/6.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "ProfileViewController.h"
#import "ItemModel.h"
#import "GroupModel.h"
#import "ItemSwitchModel.h"
#import "ItemArrowModel.h"
#import "ProfileCell.h"
#import "SettingViewController.h"


@interface ProfileViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (strong,nonatomic) NSArray *dataArray;

@end

@implementation ProfileViewController


-(NSArray *)dataArray{
    
    if (!_dataArray) {
        _dataArray = [self setData];
    }
    return _dataArray;
}

-(NSArray *)setData{
    
    //.设置数据模型
    ItemModel *item1 = [ItemModel itemWithTitle:@"热门微博" AndIconName:@"handShake"];
    item1.subTitle = @"(100)";
    GroupModel *group1 = [GroupModel groupWithItems:@[item1]];
    
    ItemModel *item21 = [ItemModel itemWithTitle:@"热门微博"AndIconName:@"lamp"];
    ItemModel *item22 = [ItemModel itemWithTitle:@"热门微博" AndIconName:@"more_historyorder"];
    GroupModel *group2 = [GroupModel groupWithItems:@[item21,item22]];
    
    ItemModel *item31 = [ItemModel itemWithTitle:@"热门微博"AndIconName:@"More_LotteryRecommend"];
    ItemModel *item32 = [ItemModel itemWithTitle:@"热门微博"AndIconName:@"MorePush"];
    ItemModel *item33 = [ItemModel itemWithTitle:@"热门微博"AndIconName:@"MoreShare"];
    GroupModel *group3 = [GroupModel groupWithItems:@[item31,item32,item33]];
    
    
    ItemModel *item41 = [ItemArrowModel itemWithTitle:@"热门微博" AndIconName:@"RedeemCode"];
    ItemModel *item42 = [ItemSwitchModel itemWithTitle:@"热门微博" AndIconName:@"sound_Effect" ];
    GroupModel *group4 = [GroupModel groupWithItems:@[item41,item42]];
    
     return @[group1,group2,group3,group4];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.设置导航栏左右按钮
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem setNavItemWithTitle:@"添加好友" target:self action:@selector(addFriend)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem setNavItemWithTitle:@"设置" target:self action:@selector(steup)];
    
    //2.设置默认注册登录界面
    //2.设置默认注册登录界面/首页界面
    if (self.defaultCenterView != nil) {
        self.defaultCenterView.iconImageName = @"visitordiscover_feed_image_house";
        self.defaultCenterView.info = @"首页";
        self.defaultCenterView.trunkImage.hidden = YES;
    }
    
    //3.设置tableView的头和尾，还有组间间距
    self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.3)];
    
    self.tableView.sectionHeaderHeight = 0;
    
    self.tableView.sectionFooterHeight = 15;
    
}


-(void)addFriend{

    DDLogDebug(@"测试");
    
}

-(void)steup{
    
    SettingViewController *setting = [[SettingViewController alloc]init];
    
    setting.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:setting animated:YES];
    
}



#pragma mark -- UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataArray.count;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    GroupModel *group = self.dataArray[section];
    
    return group.items.count;
    
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier = @"profileCell";
    
    ProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell == nil) {
        cell = [[ProfileCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier ];
    }
   
    
    GroupModel *group = self.dataArray[indexPath.section];
    
    ItemModel *item = group.items[indexPath.row];
    
    cell.item = item;
    
    return cell;
    
}


#pragma mark - UITableViewDelegate

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GroupModel *group = self.dataArray[indexPath.section];
    
    ItemModel *item = group.items[indexPath.row];
    
    
    if ([item isKindOfClass:[ItemArrowModel class]]) {
        
        ItemArrowModel *itemArrow = (ItemArrowModel *)item;
        
        UIViewController *destiController = [[itemArrow.destiController alloc]init];
        
        destiController.title = itemArrow.title;
        
        [self.navigationController pushViewController:destiController animated:YES];
        
        
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}




@end
